<%
  paginated_products = @searcher.retrieve_products if params.key?(:keywords)
  paginated_products ||= products
%>

<% content_for :head do %>
  <% if paginated_products.respond_to?(:total_pages) %>
    <%= rel_next_prev_link_tags paginated_products %>
  <% end %>
<% end %>

<div data-hook="products_search_results_heading">
  <% if products.empty? %>
    <div data-hook="products_search_results_heading_no_results_found">
      <%= Spree.t(:no_products_found) %>
    </div>
  <% elsif params.key?(:keywords) %>
    <div data-hook="products_search_results_heading_results_found">
      <h6 class="search-results-title"><%= Spree.t(:search_results, keywords: h(params[:keywords])) %></h6>
    </div>
  <% end %>
</div>

<% if products.any? %>
  <ul id="products" class="inline product-listing" data-hook>
    <% products.each do |product| %>
      <% url = spree.product_path(product, taxon_id: @taxon.try(:id)) %>
      <li id="product_<%= product.id %>" class="columns three <%= cycle("alpha", "secondary", "", "omega secondary", name: "classes") %>" data-hook="products_list_item" itemscope itemtype="http://schema.org/Product">
        <% cache(@taxon.present? ? [I18n.locale, current_pricing_options, @taxon, product] : [I18n.locale, current_pricing_options, product]) do %>
          <div class="product-image">
            <%= link_to image_tag(product.display_image.attachment(:small), itemprop: "image"), url, itemprop: 'url' %>
          </div>
          <%= link_to truncate(product.name, length: 50), url, class: 'info', itemprop: "name", title: product.name %>
          <span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
            <span class="price selling" itemprop="price"><%= display_price(product) %></span>
          </span>
        <% end %>
      </li>
    <% end %>
    <% reset_cycle("classes") %>
  </ul>
<% end %>

<% if paginated_products.respond_to?(:total_pages) %>
  <%= paginate paginated_products %>
<% end %>
